package com.zhida.smartcontrol.dialog.addqddialog;

import android.text.TextUtils;

import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

import java.util.HashMap;
import java.util.Map;

public class AddQdDialogPresenter extends BasePresenterImpl<AddQdDialogContract.View> implements AddQdDialogContract.Presenter {

    @Override
    public void addGroup(String name, String projectBaseId) {
        if (TextUtils.isEmpty(name)) {
            mView.showMsg("请输入区段名称");
            return;
        }
        Map<String, Object> params = new HashMap<>();
        params.put("id", "");
        params.put("projectBaseId", projectBaseId);
        params.put("name", name);
        params.put("description", name);
        mKalleCenter.postJson(Api.GROUP_ADD, params, true, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                mView.showMsg(msg);
                mView.onSuccess();
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }

    @Override
    public void editGroup(String name, String id, String projectBaseId) {
        if (TextUtils.isEmpty(name)) {
            mView.showMsg("请输入区段名称");
            return;
        }
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("projectBaseId", projectBaseId);
        params.put("name", name);
        params.put("description", name);
        mKalleCenter.putJson(Api.GROUP_EDIT, params, true, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                mView.showMsg(msg);
                mView.onSuccess();
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }
}
